import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

import java.util.ArrayList;
import java.util.HashMap;

public class PayrollPartitioner extends Partitioner<PayrollSortBean, Text> {
    private static int num = -1;
    private static HashMap<Integer, Integer> Dnum = new HashMap<Integer, Integer>();

    public static int DepartmentNumber(Integer I) {

        boolean b = Dnum.containsKey(I);
        if (!b) {
            Dnum.put(I, ++num);
            return num;
        } else {
            return Dnum.get(I);
        }
    }
    @Override
    public int getPartition(PayrollSortBean payrollSortBean, Text text, int i) {
        String[] split = text.toString().split(",");
        int i1 = Integer.parseInt(split[7]);
        int i2 = PayrollPartitioner.DepartmentNumber(i1);
        return i2;
    }
}